﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace Notoric.View.Music.CWNotation.Converters
{
    /// <summary>
    /// Converts a value of type <see cref="IEnumerable{T}"/> of <see cref="Point"/> to <see cref="PointCollection"/>.
    /// </summary>
    [ValueConversion(typeof(IEnumerable<Point>), typeof(PointCollection))]
    public class PointCollectionConverter : IValueConverter
    {
        /// <inheritdoc/>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is IEnumerable<Point> && targetType == typeof(PointCollection))
            {
                if (value == null)
                    throw new ArgumentNullException("value");

                var output = new PointCollection();
                foreach (var point in value as IEnumerable<Point>)
                    output.Add(point);

                return output;
            }
            else
                throw new ArgumentException("The converter can only convert from IEnumerable<Point> to PointCollection!");
        }

        /// <inheritdoc/>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
